package com.wu.controller;/**
 * @author sun
 * @date 2022/3/20 - 22:03
 */

import com.wu.pojo.Notices;
import com.wu.service.NoticesService;
import com.wu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author
 * @date 2022/3/20 22:03
 * @version 1.0
 */
@RestController
@Api(tags="Notices模块")
@CrossOrigin
@RequestMapping("notices")
public class NoticesController {

    @Autowired
    private NoticesService noticesService;

    @PostMapping("/insertNotices")
    @ApiOperation(value="增加Notices")
    public R insertNotices(@RequestBody Notices notices){
        try {
            noticesService.insertSelective(notices);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteNotices/{id}")
    @ApiOperation(value="删除Notices")
    public R deleteNotices(Integer id){
        try {
            noticesService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateNotices")
    @ApiOperation(value="更新Notices")
    public R updateNotices(@RequestBody Notices noties){
        try {
            noticesService.updateByPrimaryKeySelective(noties);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findNotices")
    @ApiOperation(value="添加查询Notices")
    public R findNotices(Notices notices){
        try {
           List<Notices> list= noticesService.findNotices(notices);
            return R.ok().data("noticesList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findNoticesById/{id}")
    @ApiOperation(value="添加查询Notices")
    public R findNoticesById(Integer id){
        try {
            Notices notices= noticesService.selectByPrimaryKey(id);
            return R.ok().data("notices",notices);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

}
